package com.skstudio.report;

import java.math.BigInteger;
import java.util.ArrayList;

public class ReportNetwork extends ReportBase {
	public static class DataNetwork {
		public BigInteger mRx = new BigInteger("0");
		public BigInteger mTx = new BigInteger("0");
		public BigInteger mDataRx = new BigInteger("0");
		public BigInteger mDataTx = new BigInteger("0");
		public int mRxRate = 0, mTxRate = 0;
		public int mDataRxRate = 0, mDataTxRate = 0;
		
		public void Read(byte[] buffer, int offset) {
			mRx = getCxxUnsignedLongLong(buffer, offset + 0);
			mTx = getCxxUnsignedLongLong(buffer, offset + 8);
			mDataRx = getCxxUnsignedLongLong(buffer, offset + 16);
			mDataTx = getCxxUnsignedLongLong(buffer, offset + 24);
		}
	}

	public ArrayList < DataNetwork > mDataList = new ArrayList < DataNetwork > ();

	@Override
	public void parse(byte[] buffer, int offset)
	{
		DataNetwork dc = new DataNetwork();
		dc.Read(buffer, offset);
		if (mDataList.size() == getMaxQueueSize()) {
			mDataList.remove(0);
		}
		if (mDataList.size() > 1) {
			DataNetwork dc2 = mDataList.get(mDataList.size() - 1);
			dc.mRxRate = dc.mRx.subtract(dc2.mRx).intValue();
			dc.mTxRate = dc.mTx.subtract(dc2.mTx).intValue();
			dc.mDataRxRate = dc.mDataRx.subtract(dc2.mDataRx).intValue();
			dc.mDataTxRate = dc.mDataTx.subtract(dc2.mDataTx).intValue();
			//String xx = String.format("mRx-mTx %s-%s, %.2f KBps %.2f KBps", dc.mRx, dc.mTx, dc.mRxRate / 1024.0, dc.mTxRate / 1024.0);
			//Log.v("DataNet", xx);
		}
		mDataList.add(dc);	
	}
	
	@Override
	public void reset() {
		mDataList.clear();
	}
}
